package utils
{
import flash.external.ExternalInterface;

public class Tracer
{	
	public static function log(data:*):void
	{
        try
        {
    		DebugSender.getInstance().sendMessage(data);
    		if (ExternalInterface.available)
    		{
    			ExternalInterface.call("flashlog", data);
    		}
        }
        catch (error:Error)
        {
            //something wrong with Tracer;
        }
	}
}
}

import flash.events.StatusEvent;
import flash.net.LocalConnection;

class DebugSender
{
	private var conn:LocalConnection;
	
	private static var instance:DebugSender;
	
	public static function getInstance():DebugSender
	{
		if(!instance) 
			instance = new DebugSender();
		
		return instance;
	}
	
	public function DebugSender()
	{
		conn = new LocalConnection();
		conn.addEventListener(StatusEvent.STATUS, onStatus);
	}
	
	public function sendMessage(message:String):void {
		conn.send("_flash_logger", "lcHandler", message);
	}
	
	private function onStatus(event:StatusEvent):void {
		switch (event.level) {
			case "status":
				//trace("LocalConnection.send() succeeded");
				break;
			case "error":
				//trace("LocalConnection.send() failed");
				break;
		}
	}
}